/*
 *文件名： MsgSink.java
 *版权： Copyright by 云天励飞 intellif.com
 *描述： Description
 *创建人：mozping
 *创建时间： 2018/8/13 9:24
 *修改理由：
 *修改内容：
 */
package com.intellif.mozping.kafka.consumer;

import com.alibaba.fastjson.JSONObject;
import com.intellif.mozping.kafka.utils.MyMsgFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.Message;

/**
 * 监听Mq消息
 *
 * @author mozping
 * @version 1.0
 * @date 2018/8/13 9:24
 * @see MqSinkReceiver
 * @since JDK1.8
 */
@EnableBinding(value = {MqSinkI.class})
public class MqSinkReceiver {

    @Autowired
    MyMsgFilter myMsgFilter;


    @StreamListener(MqSinkI.INPUT_CHANNEL)
    public void messageListen(Message<JSONObject> message) throws Exception {

//        if (message.toString().length() > 10000) {
//            throw new Exception("break.................");
//        }
        System.out.println(message.toString());

        String msgData = message.getPayload().toString();
        String msgHead = message.getHeaders().toString();


        if (myMsgFilter.filter(message)) {
            //找到了目标消息
            System.out.println("找到了目标消息...");
            System.out.println("receive msg data:" + msgData);
            System.out.println("receive msg head:" + msgHead);
        }

    }
}